import XMLParser from 'react-xml-parser';

/**
 * 将xml格式转换成json格式
 * @param xml
 * @returns {*}
 */
const toJson = (xml) =>{
    let testImg = /(<img\s+src=".+?"\s*>)/g;
    xml = xml.replace((testImg),'$1</img>');
    return new XMLParser().parseFromString(xml);
}

/**
 * 将链接字符串转换成可识别string
 * @param entity
 * @returns {string}
 */
const htmlToString = (entity) => {
    let div = document.createElement('div');
    div.innerHTML = entity;
    let res = div.innerText || div.textContent;
    return res;
}


export default {
    toJson,
    htmlToString
}